<template>
	<view class="complain-manage">
		<NavBar title="投诉管理"/>
		<view class="switch-bar">
			<view @tap="tapType(1)" class="item" :class="status==1?'a-item':''"> 全部 </view>
			<view @tap="tapType(2)" class="item" :class="status==2?'a-item':''"> 已处理 </view>
			<view @tap="tapType(3)" class="item" :class="status==3?'a-item':''"> 未处理 </view>
		</view>
		<view class="content" v-if="complainList.length">
			<view class="complain-item" v-for="(item, index) in complainList" :key="item">
				<view class="comp-title">
					<view class="comp-name"> {{item.complaint_cause}} </view>
					<view class="comp-status status-suc"> {{item.status==1?'已处理':'未处理'}} </view>
				</view>
				<view class="comp-details">
					<view class="item">
						<view class="label"> 举报商铺 </view>
						<view class="value"> {{item.name}} </view>
					</view>
					<view class="item">
						<view class="label"> 下单状态 </view>
						<view class="value"> {{item.is_pay==1?'已下单':'未下单'}} </view>
					</view>
					<view class="item">
						<view class="label"> 联系电话 </view>
						<view class="value"> {{item.mobile}} </view>
					</view>
					<view class="intro">
						<view class="intro-text"> {{item.complaint_info}} </view>
						<view class="intro-img" v-if="item.img" @tap="previewImg(item.img)"> 
							<image :src="img" v-for="img in item.img" :key="img" class="i-img"/>
						</view>
					</view>
					<view class="btn-box" v-if="item.status==0">
						<view class="btn" @tap="processed(item.id, index)"> 已处理 </view>
					</view>
				</view>
			</view>
		</view>
		<Empty txt="暂无数据~" v-else/>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onLoad,onReachBottom } from '@dcloudio/uni-app'
	import NavBar from '@/components/NavBar.vue';
	import Empty from '@/components/Empty.vue'
	import { GetComplaintListApi, EditComplaintStatusApi } from '@/service/agent.js'
	import { previewImg } from '@/utils/index.js'
	const status = ref(1)
	const page = ref(1)
	const pageSize = ref(15)
	const total = ref(0)
	const complainList = ref([])
	const tapType = (index) => {
		if(status.value == index) return
		status.value =index
		page.value = 1
		complainList.value = []
		getComplaintList()
	}
	const complaintList = ref([])
	// 获取投诉列表
	const getComplaintList = () => {
		GetComplaintListApi({status: status.value}).then(res => {
			total.value = res.total
			complainList.value.push(...res.data)
		})
	}
	// 已处理
	const processed = (id, i) => {
		EditComplaintStatusApi({id}).then(res => {
			if(status.value ==2 || status.value ==3) return complainList.value.splice(i, 1)
			complainList.value[i].status = 1
		})
	}
	onLoad(() => {
		getComplaintList()
	})
	onReachBottom(() => {
		if(page.value*pageSize.value>=total.value) return
		page.value = page.value + 1
		getComplaintList()
	})
</script>

<style lang="scss" scoped>
	.complain-manage {
		.switch-bar {
			height: 34px;
			display: flex;
			.item {
				flex: 1;
				color: #333333;
				font-size: 14px;
				line-height: 34px;
				font-weight: 400;
				text-align: center;
				&.a-item {
					color: #FF3B1E;
					font-size: 16px;
					font-weight: 500;
					position: relative;
					&::before {
						display: block;
						content: '';
						position: absolute;
						bottom: 0;
						left: 50%;
						transform: translateX(-50%);
						width: 26px;
						height: 4px;
						border-radius: 33px;
						background: linear-gradient( 360deg, #FF8508 0%, #FF4847 100%);
					}
				}
			}
		}
		.content {
			padding: 16px 12px;
			.complain-item {
				border-radius: 10px;
				margin-bottom: 10px;
				background-color: #fff;
				box-sizing: border-box;
				padding: 15px 12px 10px;
				.comp-title {
					display: flex;
					align-items: center;
					padding-bottom: 10px;
					justify-content: space-between;
					border-bottom: 1px solid #EEEEEE;
					.comp-name {
						font-size: 14px;
						color: #333333;
						line-height: 17px;
					}
					.comp-status {
						font-weight: 400;
						font-size: 14px;
						color: #FF3B1E;
						line-height: 17px;
						&.status-suc {
							color: #999999;
						}
					}
				}
				.comp-details {
					padding-top: 10px;
					.item {
						display: flex;
						font-size: 14px;
						font-weight: 400;
						line-height: 19px;
						align-items: center;
						margin-bottom: 12px;
						justify-content: space-between;
						.label {
							color: #666666;
						}
						.value {
						  color: #333333;
						}
					}
					.intro {
						.intro-text {
							color: #999999;
							font-size: 14px;
							font-weight: 400;
							line-height: 20px;
							margin-bottom: 10px;
						}
						.intro-img {
							.i-img {
								width: 74px;
								height: 74px;
								margin-right: 20px;
								border-radius: 10px;
							}
						}
					}
					.btn-box {
						display: flex;
						justify-content: end;
						.btn {
							width: 80px;
							height: 32px;
							color: #FFFFFF;
							font-size: 14px;
							font-weight: 400;
							line-height: 32px;
							text-align: center;
							background: #FF3B1E;
							border-radius: 151px;
						}
					}
				}
			}
		}
	}
</style>
